package com.atguigu.day04;

import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

//锁降级     在当前线程拥有写锁的情况下,获取到读锁,随后释放写锁的过程就是锁降级
public class ReadWriteLockDemo2 {


    public static void main(String[] args) {
        ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
        readWriteLock.writeLock().lock();
        try {
            System.out.println("获取写锁....");
            //获取读锁
            readWriteLock.readLock().lock();
            System.out.println("获取读锁...");
        }finally {
            readWriteLock.writeLock().unlock();
            System.out.println("释放写锁....");
            readWriteLock.readLock().unlock();
            System.out.println("释放读锁");
        }

    }
}
